package relu.fbs.jfm;

import java.util.Map;


import relu.fbs.DataValue;

public class JFMCropDataTSAv extends AbstractJFMCropData {

	/** Create a new average using the first JFMCropData as a template. 
	 * Adds the first set of data into the average. */
	public JFMCropDataTSAv(JFMCropData first){
		super(first.cropType);
		// All data values are treated as intensive in a time series average
		for(JFMCDatum d:JFMCDatum.values()){
			DataValue dv=new DataValue(true);
			dv.add(first.data.get(d).autoValue());
			data.put(d, dv);
		}
	}
	
	/** Add a CropData object to this time average.  All data is averaged including extensive variables */
	public void increment(JFMCropData indata){
		double wgt=1.0; // each year gets a weight of 1
		for ( Map.Entry<JFMCDatum, DataValue> entry:indata.data.entrySet()){
			JFMCDatum key=entry.getKey();
			DataValue val=entry.getValue();
			if ( key.isIntensive){
				data.get(key).add(val.avValue(),wgt);
			} else {
				data.get(key).add(val.sumValue(),wgt);
			}
		}
	}
	
}
